﻿var m_project_id = '';
var m_xkzh = '';
var m_obj = null;
var sfmap = null;
$("document").ready(function () {
    m_project_id = $.query.get("Project_ID");
    var blhj = $.query.get("BLHJ");
    if (blhj != "SLXM") {
        //SetFMReadonly();
        $(".m_btn").addClass("nosee");
    }
    else {
        $("input.dateinput").click(function () { WdatePicker({ dateFmt: 'yyyy-M-d' }); });
    }
    sfmap = new sfMap("id_div_map");
    if (m_project_id != null && m_project_id != '') {
        var dbalias = "CKQDJK";
        var tablename = "采矿申请登记";
        var condittion = "PROJECT_ID=\\\'" + m_project_id + "\\\'";
        m_obj = new SmObjectData("CKQDJK", "采矿申请登记");
        m_obj.GetFirstSmObject(condittion);
        InitSQB();
    }
});
function InitSQB() {
    var obj = m_obj;
    for (i = 0; i < obj.Data.Data.length; i++) {
        var key = obj.Data.Data[i].Key;
        var value = obj.Data.Data[i].Value;
        if ($("input[name='txt" + key + "']") != null) {
            $("[name='txt" + key + "']").val(value);
        }
        if (key == "QYZB") {
            $("tr[tag='useradd']").remove();
            var values = value.split(',');
            var zbs = GetZBC(values);
            var j = 0;
            for (j = 0; j < zbs.length - 1; j++) {
                var str = '<tr tag="useradd"><td >' + zbs[j].xh + '</td><td ><input value="' + zbs[j].y + '" class="txtinput" /></td>\
                                <td><input value="' + zbs[j].x + '"  class="txtinput" /></td></tr>';
                $("#id_zb_table").append(str);

            }
            sfmap.addGeometry(zbs);
        }
    }
}

function GetZB(str) {

}
function SetFMReadonly() {
    $("input").attr("readonly", "readonly");
}

function GetZBC(kqfws) {
    var list = new Array();
    var ds = parseInt(kqfws[1]);
    var curpos = 2;
    var xh = 1;
    var i = 0;
    while (ds > 0) {
        for (i = 0; i < ds; i++) {
            var row = new ZBROW();
            row.xh = xh;
            row.gdh = kqfws[curpos];
            row.y = kqfws[curpos + 1];
            row.x = kqfws[curpos + 2];
            row.ktbs = "";
            row.xz = "";
            xh++;
            curpos += 3;
            list[list.length] = row;
        }
        var row2 = new ZBROW();
        row2.xh = xh;
        xh++;
        row2.gdh = "*";
        row2.y = kqfws[curpos];
        row2.x = kqfws[curpos + 1];
        row2.ktbs = kqfws[curpos + 2];
        row2.xz = kqfws[curpos + 3];
        curpos += 4;
        // list[list.length]=row2;
        ds = 0;
        if (curpos != kqfws.length - 1) {
            ds = parseInt(kqfws[curpos]);
            curpos++;
        }
        ds = -1;
    }
    return list;

}
function saveZB() {
    var str = "采深上限,采深下限,矿区面积,CKQSYF";
    if (m_obj != null) {
        var strs = str.split(',');
        for (i = 0; i < strs.length; i++) {
            m_obj.SetValue(strs[i], $("[name='txt" + strs[i] + "']").val() == null ? "" : $("[name='txt" + strs[i] + "']").val());
        }
        var strzb = GetSTRZB();
        alertex(m_obj.Update());
    }
}
function GetSTRZB() {

}

function ZBROW() {
    this.xh = '';
    this.x = '';
    this.y = '';
    this.ktbs = '';
    this.xz = '';
}
